<template>
  <div>
    <el-row id="top" :span="12" type="flex" align="middle">
            <el-col :span="5">
              <el-input @keyup.enter.native="searchOne()" v-model="search" placeholder="请输入用户名"></el-input>
            </el-col>
            <el-col :span="2">
              <el-button type="primary" icon="el-icon-search" @click="searchOne()" size="small">搜索</el-button>
            </el-col>
            <el-col :span="2">
              <el-button type="primary" icon="el-icon-check" @click="accessAll()" size="small">批量通过</el-button>
            </el-col>
      <el-col :span="12">
        <div class="grid-content bg-purple-light"></div>
      </el-col>
    </el-row>
    <div style="height:20px"></div>
    <el-table ref="multipleTable" :data="lenddetails" tooltip-effect="dark" style="width: 100%" height="70vh" border
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="80" align="center"></el-table-column>
      <el-table-column prop="id" label="编号" width="135" align="center"></el-table-column>
      <el-table-column prop="username" label="用户名" width="135" align="center"></el-table-column>
      <el-table-column prop="itemid" label="器材编号" width="135" align="center"></el-table-column>
      <el-table-column prop="num" label="数量" width="135" align="center"></el-table-column>
      <el-table-column prop="applytime" label="申请时间" width="160" align="center"></el-table-column>
      <el-table-column label="操作" align="center" width="135">
        <template slot-scope="scope">
          <el-button icon="el-icon-check" type="success" size="mini"
            @click="accessOne(scope.$index, scope.row)">通过</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<style>
.el-table__header .el-table-column--selection .cell .el-checkbox::after {
  color: #909399;
  font-family: Avenir, Helvetica, Arial, sans-serif;
  content: "全选";
  font-size: 14px;
  margin-left: 12px;
  font-weight: bold;
  }
</style>
<script>
export default {
  data() {
    return {
      lenddetails: [{
        id: '',
        username: '',
        itemid: '',
        num: '',
        applytime: '',
        lendtime: '',
        returntime: '',
        state: '',
      }],
      search: '',
      multipleSelection: [],
    };
  },

  created: function () {
    this.start();
  },
  mounted() {
    window.history.forward(1);
  },
  methods: {
    start() {
      this.$axios
        .get("http://localhost:8085/selectApplication")
        .then((response) => {
          console.log(response.data);
          this.lenddetails = response.data;
        });
    },
    accessOne(index, row) {
      this.$confirm('是否通过', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios
        .get("http://localhost:8085/accessApplication?id=" + row.id)
        .then((response) => {
          if (response.data != null) {
            console.log(response.data);
            this.lenddetails = response.data;
            this.$message.success("通过了"+row.username+"的申请");
          }
        });
      }).catch(() => {
      });
  
    },
    accessAll() {
      console.log("accessALL："+this.multipleSelection);
      if(this.multipleSelection!='')
      {
        this.$confirm('是否通过', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios
        .post("http://localhost:8085/accessAllApplication?", this.multipleSelection)
        .then((response) => {
          console.log(response.data);
          this.lenddetails = response.data;
          this.$message.success("已全部通过");
        });
      }).catch(() => {
      });
      }
      else
      {
        this.$message.error("未选择");
      }
      

     
    },
    searchOne() {
      if (this.search != '') {
        this.$axios
          .get("http://localhost:8085/selectApplicationByUsername?username=" + this.search)
          .then((response) => {
            console.log(response.data);
            this.lenddetails = response.data;
          });
      }
      else {
        this.start();
      }

    },
    filterTag(value, row) {
      return row.state === value;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log(val);
    },
  },
};
</script>
   
   